home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Magazine 28 Bonus / CDRomMagazine-SoftKey-ArtPassion-FrenchVersion-Win31Mac.bin / data / crmixpl.dir / 00085_Script_COLOR WHEEL PLAY < prev    next >
Text File  |  1996-05-07  |  9KB  |  269 lines

  1. -- ---------------------------------------------------------------
  2. -- Handler addColorToGuess (1) adds the clicked color to the list of
  3. -- colors clicked, (2) mixes the color with the user's guess, and
  4. -- (3) checks if the color the user mixed is correct.
  5.  
  6. on addColorToGuess whichColor
  7.   updatePrimaryUsed(whichColor)
  8.   
  9.   addColorToAnswerCombination(whichColor)
  10.   changeAnswerColor
  11.   checkColorWheelResult
  12. end
  13.  
  14. -- ---------------------------------------------------------------
  15. -- Handler addColorToAnswerCombination adds the given color to the
  16. -- combination of colors clicked (stored as a string in the global
  17. -- variable answerCombination - of the form BxRzYw where x is the
  18. -- number of times blue was clicked, z is the number of times red
  19. -- was clicked, and w is the number of times yellow was clicked).  
  20.  
  21. on addColorToAnswerCombination whichColor 
  22.   global answerCombination
  23.   
  24.   if whichColor = "B" then
  25.     set whichChar = 2 
  26.   else if whichColor = "R" then
  27.     set whichChar = 4
  28.   else if whichColor = "Y" then
  29.     set whichChar = 6
  30.   end if
  31.   
  32.   set numClickedSoFar = value(char whichChar of answerCombination)
  33.   set numClickedSoFar = numClickedSoFar + 1
  34.   put string(numClickedSoFar) into char whichChar of answerCombination
  35. end
  36.  
  37. -- ---------------------------------------------------------------
  38. -- Handler changeAnswerColor changes the color of the user's guess
  39. -- to the given color by first setting the  foreColor and backColor
  40. -- of guessSprite to the mixedColor represented by answerCombination.
  41. -- PalleteNumbers is a global variable containing a list of all
  42. -- possible combinations of blues, reds and yellows and the pallete
  43. -- number representing the combination. The colors are listed 
  44. -- in boolean form starting with B0R0Y1 and ending in B3R3Y3. The
  45. -- following formula can be used to determine the line number used
  46. -- for any given answerCombination: (B*16) + (R*4) + Y.
  47.  
  48. on changeAnswerColor mixedColor
  49.   global palleteNumbers, guessSprite, answerCombination
  50.   
  51.   set palleteLine = (16*value(char 2 of answerCombination)) + (4*value(char 4 of answerCombination)) + value(char 6 of answerCombination)
  52.   
  53.   set newPalleteNumber = value(word 2 of line palleteLine of palleteNumbers)
  54.   set the foreColor of sprite guessSprite = newPalleteNumber
  55.   set the backColor of sprite guessSprite = newPalleteNumber
  56.   updateStage
  57. end
  58.  
  59. -- ---------------------------------------------------------------
  60. -- Handler checkColorWheelResult checks if the user correctly mixed
  61. -- the colors to get the answer color.  If so, the handler adds the
  62. -- mixed color to the color wheel and sets the game with a new color.
  63. -- If not, the global variable answerCombination is set to the mixed color.
  64. -- This allows the user to make colors such as greenYellow from 2 yellows
  65. -- and blue and not just from green and yellow.
  66.  
  67. on checkColorWheelResult mixedColor
  68.   global guessSprite, answerSprite, answerPalleteNum
  69.   
  70.   if the backColor of sprite guessSprite = answerPalleteNum then
  71.     beep
  72.     addColorToWheel
  73.     
  74.         startTimer
  75.         repeat while the timer < 40
  76.               nothing
  77.         end repeat
  78.     
  79.     -- checkGameOver
  80.     getNextColor
  81.   end if
  82. end
  83.  
  84. -- ---------------------------------------------------------------
  85. -- Handler addColorToWheel adds the color of the given sprite to
  86. -- the color wheel by setting the visible property of the sprite
  87. -- to TRUE.
  88.  
  89. on addColorToWheel
  90.   global answerCombination
  91.   
  92.   set colorSprite = answerCombination & "Sprite"
  93.   if the visible of sprite value(colorSprite) = FALSE then
  94.     set the visible of sprite value(colorSprite) = TRUE
  95.     updateStage
  96.   end if
  97. end
  98.  
  99. -- ---------------------------------------------------------------
  100. -- Handler getNextColor takes the next color randomly from the global
  101. -- variable possibleColorsList (property list where the name of each
  102. -- property is a color and the value of each property is the pallete
  103. -- number of the color).
  104.  
  105. on getNextColor
  106.   global answerSprite, answerPalleteNum
  107.   global possibleColorsList
  108.   
  109.   clearAnswer
  110.   if count(possibleColorsList) > 0 then
  111.     set answerColorPosition = random(count(possibleColorsList))
  112.     set answerColorName = getPropAt(possibleColorsList,answerColorPosition)
  113.     set answerPalleteNum = getProp(possibleColorsList, answerColorName)
  114.     
  115.     -- delete color user has to guess from the list
  116.     deleteProp (possibleColorsList, answerColorName)
  117.     
  118.     -- add new possible colors to possibleColorsList
  119.     updatePossibleColorsList(answerColorName)
  120.     
  121.     set the backColor of sprite answerSprite = answerPalleteNum
  122.     set the foreColor of sprite answerSprite = answerPalleteNum
  123.     clearPrimaryUsed
  124.     updateStage
  125.   else
  126.     winColorWheelGame
  127.   end if
  128. end
  129.  
  130. -- ---------------------------------------------------------------
  131. -- Handler clickTryAgain is called when the user clicks on the try
  132. -- again button
  133.  
  134. on clickTryAgain
  135.   activateButton(the clickOn)
  136.   clearAnswer
  137. end
  138.  
  139. -- ---------------------------------------------------------------
  140. -- Handler clearAnswer is called either when the user clicks the
  141. -- clear button or when the user correctly mixes the colors to
  142. -- get the answer color.  This handler resets the color of the user's
  143. -- guess to white and resets the global variable answerCombination
  144. -- (that stores the colors the user clicked) to the empty string.
  145.  
  146. on clearAnswer
  147.   global answerCombination, guessSprite
  148.   
  149.   -- change the color of their guess back to white
  150.   clearPrimaryUsed
  151.   set the backColor of sprite guessSprite = 0
  152.   set the foreColor of sprite guessSprite = 255 -- black outline
  153.   updateStage
  154.   set answerCombination = "B0R0Y0"
  155. end
  156.  
  157. -- ---------------------------------------------------------------
  158. -- Handler updatePossibleColorsList updates the global variable
  159. -- (property list) possibleColorsList by adding new makable
  160. -- colors to the list (i.e. if the user just created B1Y1 (green) and
  161. -- green was added to the color wheel, B2Y1 and B1Y2 will be added
  162. -- to possibleColorsList).  Each time a color is added to the color
  163. -- wheel, 1 or 2 new colors are added to possibleColorsList (the new
  164. -- color mixed with 1 or both of the 2 primary colors used to make it)
  165.  
  166. on updatePossibleColorsList newlyAddedColor
  167.   global possibleColorsList
  168.   
  169.   set newColors = field "newColors"
  170.   
  171.   repeat with i = 1 to the number of lines in newColors
  172.     if (item 1 of line i of newcolors = newlyAddedColor) then
  173.       repeat with j = 2 to the number of items in line i of newColors
  174.         addProp (possibleColorsList, word 1 of item j of line i of newColors, value(word 2 of item j of line i of newColors))
  175.       end repeat -- j
  176.       exit repeat -- i
  177.     end if
  178.   end repeat
  179. end
  180.  
  181. -- ---------------------------------------------------------------
  182. -- Handler updatePrimaryUsed updates the global variables keeping
  183. -- record of the number of primary colors used so far.
  184.  
  185. on updatePrimaryUsed whichColor
  186.   global numBlue, numRed, numYellow
  187.   global numBSprite, numRSprite, numYSprite
  188.   
  189.   set whichSprite = value("num" & whichColor & "Sprite")
  190.   set numUsed = value(char 1 of the name of cast the castNum of sprite whichSprite)
  191.   set numUsed = numUsed + 1
  192.   if (numUsed > 3) then
  193.     doUsedTooMany(whichColor)
  194.     clearAnswer  
  195.     abort -- addColorToGuess
  196.   else
  197.     set newCast = numUsed & whichColor
  198.     set the castNum of sprite whichSprite = the number of cast newCast
  199.     updateStage
  200.   end if
  201. end
  202.  
  203. -- ---------------------------------------------------------------
  204. -- Handler clearPrimaryUsed resets to 0 the global variables keeping
  205. -- track of the number of primary colors used so far.
  206.  
  207. on clearPrimaryUsed
  208.   global numBlue, numRed, numYellow
  209.   global numBSprite, numRSprite, numYSprite
  210.   
  211.   set numBlue = 0
  212.   set numRed = 0
  213.   set numYellow = 0
  214.   
  215.   set the castNum of sprite numBSprite = the number of cast "0B"
  216.   set the castNum of sprite numRSprite = the number of cast "0R"
  217.   set the castNum of sprite numYSprite = the number of cast "0Y"
  218.   -- stage is updated when this handler is called so it
  219.   -- doesn't ha